package com.tanhua.server.controller;

import com.tanhua.model.vo.SoulPaperVo;
import com.tanhua.model.vo.SoulReportVo;
import com.tanhua.server.service.TestSoulService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 测灵魂
 */
@Slf4j
@RestController
@RequestMapping("/testSoul")
public class TestSoulController {
    @Autowired
    private TestSoulService testSoulService;

    //题目列表
    @GetMapping
    public ResponseEntity getTestSoul() {
        List<SoulPaperVo> list = testSoulService.testSoul();
        log.info("试卷集合{}", list.toString());
        return ResponseEntity.ok(list);
    }

    //提交问卷
    @PostMapping
    public ResponseEntity postTestSoul(@RequestBody Map map) {

        List<Map> answers = (List<Map>) map.get("answers");
        log.info(answers.toString());

        String id = testSoulService.postTestSoul(answers);


        return ResponseEntity.ok(id);
    }

    //查看问卷
    @GetMapping("/report/{id}")
    public ResponseEntity report(@PathVariable("id") String id) {

        SoulReportVo soulReport = testSoulService.report(Long.valueOf(id));
        return ResponseEntity.ok(soulReport);
    }
}

